{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="tablesWrap">
    <div class="tables-searchbox">
    <form method="post">
        <span class="tbs-txt">客户名称：</span>
        <input type="text" name="customer_name" value="{$customer_name}">

        <span class="tbs-txt">业务员：</span>
        <input type="text" name="salesman" value="{$salesman}">

        <select name="customer_type">
            <option value="0" selected="">-客户性质-</option>
            {foreach from=$customer_type_list key=key item=type}
            <option value="{$key}" {if $customer_type EQ $key}selected{/if}>{$type}</option>
            {/foreach}
        </select>

        <select name="follow_state">
            <option value="-1" selected="">-跟进状态-</option>
            {foreach from=$follow_state_list item=row key=key}
            <option value="{$key}" {if $key EQ $follow_state}selected{/if}>{$row}</option>
            {/foreach}
        </select>

        <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
        <!--<div class="mgt10">-->
            <!--<span class="tbs-txt">添加时间：</span>-->
            <!--<input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">-->
            <!--<span class="tbs-txt">至</span>-->
            <!--<input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker()">-->
        <!--</div>-->
    </form>
</div>
    <!-- end tables-searchbox -->



    <table class="wxtables">
        <colgroup>
            <!--<col width="6%">-->
            <col width="10%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="8%">
            <col width="10%">
            <col width="8%">
            <col width="8%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            <!--<td>选择</td>-->
            <td>客户姓名</td>
            <td>客户性质</td>
            <td>联系人</td>
            <td>职务</td>
            <td>手机号码</td>
            <td>客户等级</td>
            <td>初步洽谈时间</td>
            <td>跟进状态</td>
            <td>业务员</td>
            <td>操作</td>
        </tr>
        </thead>
        {foreach from=$customer_list item=this}
        <tbody class="combo-tbody">
        <tr>
            <!--<td><input type="checkbox" class="checkbox" name="a[]" value="{$this.customer_id}"></td>-->
            <td>{$this.customer_name}</td>
            <td>{$this.customer_type_name}</td>
            <td>{$this.likeman}</td>
            <td>{$this.post}</td>
            <td>{$this.mobile}</td>
            <td>{$this.level_name}</td>
            <td>{if $this.first_talk_time}{$this.first_talk_time|date_format:'%Y-%m-%d %H:%M'}{else}--{/if}</td>
            <td>{$this.follow_state_name}</td>
            <td>{$this.user_name}</td>
            <td>
                <a href="/AcpCustomer/add_edit_customer/customer_id/{$this.customer_id}.html" class="btn" title="修改">修改</a>
                <a href="/AcpCustomer/detail_customer/customer_id/{$this.customer_id}.html" class="btn" title="详情">详情</a>

                <a href="/AcpCustomer/get_talk_summary_list/customer_id/{$this.customer_id}.html" class="btn" title="查看沟通纪要">查看沟通纪要</a>
                {if $user_id == 1}
                <a href="javascript:;" onclick="set_salesman({$this.customer_id})" class="btn" title="设置业务员">设置业务员</a>
                {/if}
                <!--<a href="javascript:;" class="btn" title="删除" onclick="delete_service_type({$this.service_type_id})">删除</a>-->
            </td>
        </tr>
        </tbody>
        {foreachelse}
        <tbody>
        <tr>
            <td colspan="7">
                没有符合条件的记录
            </td>
        <tr>
        </tbody>
        {/foreach}
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <!--<div class="fl">-->
            <!--<a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>-->
            <!--<a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>-->
            <!--<a href="javascript:;" onclick="batch_delete()" class="btn btn-blue">删除</a>-->
        <!--</div>-->
        <div class="fr">
            <div class="paginate">
                {$page_str}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>

{literal}
<script>
    //全选
    function Select() {
        var sel = document.getElementsByName("a[]");
        for (var i = 0; i < sel.length; i++) {
            sel[i].checked = true;
        }
    }
    //取消全选
    function Cancel() {
        var sel = document.getElementsByName("a[]");
        for (var i = 0; i < sel.length; i++) {
            sel[i].checked = false;
        }
    }

    function delete_service_type(type_id) {
        $.jPops.confirm(
                {
                    title: "提示",
                    content: "您确定要删除这条数据吗？",
                    okBtnTxt: "确定",
                    cancelBtnTxt: "取消",
                    callback: function (r) {
                        if (r) {
                            $.post('/AcpServiceType/delete_service_type', {"service_type_id": type_id}, function (data, textStatus) {
                                if (data == 'success') {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else {
                                    alert('对不起，服务类型下存在服务商，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }

    function batch_delete() {
        $.jPops.confirm(
                {
                    title: "提示",
                    content: "您确定要删除这些数据吗？",
                    okBtnTxt: "确定",
                    cancelBtnTxt: "取消",
                    callback: function (r) {
                        if (r) {
                            var service_type_ids = '';
                            var count = 0;
                            $('input[name="a[]"]:checked').each(function () {
                                count++;
                                service_type_ids += $(this).val() + ',';
                            });

                            if (!count) {
                                alert('对不起，请选择至少一项进行删除！');
                                return;
                            }

                            service_type_ids = service_type_ids.substr(0, service_type_ids.length - 1);

                            $.post('/AcpServiceType/batch_delete_service_type', {"service_type_ids": service_type_ids}, function (data, textStatus) {
                                if (data == 'success') {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else {
                                    alert('对不起，服务类型下存在服务商，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }
</script>
{/literal}


{literal}
<script>
    function set_salesman(obj_id) {
        var html='';

        var html='<form id="deliver_form">' +
                '<div class="formitems inline">'+
                '<label class="fi-name"><span class="colorRed">*</span>业务员：</label>'+
                '<div class="form-controls">'+
                '<select class="small" name="salesman" id="salesman">'+
                {/literal}
        '<option value="">--选择业务员--</option>'+
        {foreach from=$user_list key=key item=user}
        '<option value="{$user.user_id}">{$user.realname}</option>'+
        {/foreach}
        {literal}
        '</select><span class="fi-help-text"> </span>'+
        '</div>' +
        '</div>'+
        '<input type="hidden" name="obj_id" value="'+obj_id+'">'+
        '</form>';

        $.jPops.custom({
            title:"设置",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r)
                {

                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpCustomer/set_salesman',$('#deliver_form').serialize(),function(data)
                                    {
                                        if (data == 'success')
                                        {
                                            alert('恭喜您，操作成功');
                                            location.reload();
                                        }
                                        else
                                        {
                                            alert('对不起，操作失败');
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    //表单验证规则
                    $("#deliver_form").validate(
                            {
                                rules:
                                {
                                    salesman:
                                    {
                                        required: true,
                                    },
                                },
                                messages:
                                {
                                    salesman:
                                    {
                                        required: "对不起，请选择业务员",
                                    },
                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#deliver_form").submit();
                    return acp.batchDeliverFormStatus;
                }
                else
                {
                    return true;
                }
            }
        });
    }
</script>
{/literal}



{/block}

{block name="css"}
<link type="text/css" rel="stylesheet" href="__ACPCSS__/tip.css"/>
{literal}
<style>
    .PageNext {
        page-break-after: always;
        height: 1px;
    }
</style>
{/literal}
{/block} 
